home *** CD-ROM | disk | FTP | other *** search
/ Game.EXE 2001 February / GAME_2.ISO / utilities / Opera 5.01 / Opera501_final_nonjava.exe / OPERA.JAR / opera / OperaOutputStream.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-12-07  |  2.0 KB  |  90 lines

  1. package opera;
  2.  
  3. import java.io.IOException;
  4. import java.io.OutputStream;
  5. import java.util.Hashtable;
  6.  
  7. class OperaOutputStream extends OutputStream {
  8.    private static final int BUFFER_SIZE = 16384;
  9.    private static Hashtable stream_map = new Hashtable();
  10.    private static int next_stream_id = 0;
  11.    private byte[] buffer = new byte[16384];
  12.    private int next_write_byte = 0;
  13.    private int stream_id = -1;
  14.    protected int istream_id = -1;
  15.    private OperaURLConnection connection = null;
  16.  
  17.    protected OperaOutputStream(OperaURLConnection var1) {
  18.       this.connection = var1;
  19.    }
  20.  
  21.    public void write(int var1) throws IOException {
  22.       if (this.buffer == null) {
  23.          throw new IOException();
  24.       } else {
  25.          this.buffer[this.next_write_byte++] = (byte)var1;
  26.          if (this.next_write_byte == 16384) {
  27.             this.flushBuffer();
  28.          }
  29.  
  30.       }
  31.    }
  32.  
  33.    public void flush() throws IOException {
  34.       if (this.buffer == null) {
  35.          throw new IOException();
  36.       } else {
  37.          this.flushBuffer();
  38.       }
  39.    }
  40.  
  41.    public void close() throws IOException {
  42.       if (this.buffer != null) {
  43.          this.write(0);
  44.          this.flushBuffer();
  45.          this.postData(this.istream_id, this.connection.makeExtraHeaders());
  46.          this.connection = null;
  47.          this.buffer = null;
  48.       } else {
  49.          throw new IOException();
  50.       }
  51.    }
  52.  
  53.    private void flushBuffer() {
  54.       if (this.next_write_byte > 0) {
  55.          this.addData(this.buffer, this.next_write_byte);
  56.          this.next_write_byte = 0;
  57.       }
  58.  
  59.    }
  60.  
  61.    private native void postData(int var1, String var2);
  62.  
  63.    private native void addData(byte[] var1, int var2);
  64.  
  65.    protected static int addStream(OperaOutputStream var0) {
  66.       Hashtable var1 = stream_map;
  67.       synchronized(var1) {
  68.          stream_map.put(new Integer(next_stream_id), var0);
  69.          var0.stream_id = next_stream_id++;
  70.       }
  71.  
  72.       return var0.stream_id;
  73.    }
  74.  
  75.    protected static void removeStream(int var0) {
  76.       Hashtable var1 = stream_map;
  77.       synchronized(var1) {
  78.          stream_map.remove(new Integer(var0));
  79.       }
  80.    }
  81.  
  82.    protected static OperaOutputStream getStream(int var0) {
  83.       Hashtable var1 = stream_map;
  84.       synchronized(var1) {
  85.          OperaOutputStream var2 = (OperaOutputStream)stream_map.get(new Integer(var0));
  86.          return var2;
  87.       }
  88.    }
  89. }
  90.